package com.fyzk.activity.user.coupon;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.bean.CouponListBean;
import com.tyjc.lottery.R;

/**
 * Created by fanxs11 on 17/1/23.
 *
 * 优惠劵item
 */
public class CouponAdapter extends BaseAdapter {

    private Context context;

    public CouponAdapter(Context context) {
        this.context = context;
    }


    @Override
    public int getCount() {
        return CouponActivity.infos.size();
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Object getItem(int i) {
        return CouponActivity.infos.get(i);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        HolderView holderView;
        CouponListBean.CouponsBean info = CouponActivity.infos.get(i);
        if (view == null) {
            holderView = new HolderView();
            view = LayoutInflater.from(context).inflate(R.layout.coupon_item, null);
            holderView.ll = (LinearLayout) view.findViewById(R.id.coupon_item_ll);
            holderView.name_tv = (TextView) view.findViewById(R.id.coupon_item_name);
            holderView.time_tv = (TextView) view.findViewById(R.id.coupon_item_time);
            holderView.name2_tv = (TextView) view.findViewById(R.id.coupon_item_name2);
            holderView.iv = (ImageView) view.findViewById(R.id.coupon_item_iv_icon);
            view.setTag(holderView);
        } else {
            holderView = (HolderView) view.getTag();
        }

        if (info.getStatus().equals("1")) {
            holderView.ll.setBackgroundResource(R.drawable.coupon_item_nouse_bg);
            holderView.name_tv.setTextColor(context.getResources().getColor(R.color.color_fa5e38));
            holderView.iv.setVisibility(View.GONE);
        } else if (info.getStatus().equals("2")) {
            holderView.ll.setBackgroundResource(R.drawable.coupon_item_overdue_bg);
            holderView.name_tv.setTextColor(context.getResources().getColor(R.color.color_b4b1aa));
            holderView.iv.setImageResource(R.drawable.coupon_item_ysy_icon);
            holderView.iv.setVisibility(View.VISIBLE);
        } else if (info.getStatus().equals("3")) {
            holderView.ll.setBackgroundResource(R.drawable.coupon_item_overdue_bg);
            holderView.name_tv.setTextColor(context.getResources().getColor(R.color.color_b4b1aa));
            holderView.iv.setImageResource(R.drawable.coupon_item_ygq_icon);
            holderView.iv.setVisibility(View.VISIBLE);
        }

        holderView.name_tv.setText(info.getTitle());
        if (info.getEndDate().length() > 10) {
            holderView.time_tv.setText(info.getEndDate().substring(0, 10));  //去掉 00:00:00,只显示 2016-04-25
        }else {
            holderView.time_tv.setText(info.getEndDate());
        }
        holderView.name2_tv.setText("满"+info.getOrderamt()+"减"+info.getDisamt());
        return view;
    }

    class HolderView{
        LinearLayout ll;
        TextView name_tv;
        TextView time_tv;
        TextView name2_tv;
        ImageView iv;
    }
}
